<template>
    <el-dialog v-if="dialogVisible" :close-on-click-modal='false' :title="name+'数据导出'" :visible.sync="dialogVisible" @close="resetForm('subForm')" width="400px">
        <el-form label-position="top" :model="subForm" :hide-required-asterisk='true' ref="subForm" :rules="addRules" class="dialog_form">
            <el-form-item label="时间范围" prop="date">
                <el-date-picker value-format="yyyy-MM-dd" v-model="subForm.date" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期">
                </el-date-picker>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button size="small" @click="resetForm('subForm')" class="el-button-width">取 消</el-button>
            <el-button size="small" type="primary" @click="submitForm('subForm')" :disabled="loading" :loading="loading" class="el-button-width">确 认</el-button>
        </span>
    </el-dialog>
</template>

<script>
export default {
    name: "",
    data() {
       
        return {
            name:"",
            loading: false,
            dialogVisible: false,
            subForm: {
                id:  null,
                date: "",
            },
            addRules: {
                date: [
                    {
                        required: true,
                        message: "请选择时间",
                        trigger: ["blur", "change"],
                    },
                ],
            },
        };
    },
    created() {
        
    },
    methods: {
        getData(row){
            this.dialogVisible = true
            this.name = row.brand_name
            this.subForm.id = row.id
        },
        // 提交添加
        submitForm(formName) {
            this.$refs[formName].validate(async (valid) => {
                if (valid) {
                    this.loading = true;
                    const { data: res } = await this.$http.post(
                        "adminapi/project/exportAnalysisReport",
                        this.subForm
                    );
                    if (res.code !== 200) {
                        this.$message.error(res.msg);
                        this.loading = false;
                        return;
                    } else {
                        this.$message({
                            message: "导出成功",
                            type: "success",
                        });
                        this.loading = false;
                        this.resetForm(formName);
                    }
                } else {
                    this.loading = false;
                    return false;
                }
            });
        },

        // 关闭重置表单
        resetForm(formName) {
            this.$refs[formName].resetFields();
            this.dialogVisible = false;
        },
    },
    components: {},
};
</script>


<style scoped>
</style>
